/**
* Roots includes
*/
DEFINE('THMV_ALOHA_PLUGIN_FILE','aloha-powerpack/aloha-powerpack.php');//aloha-powerpack/aloha-powerpack.php
DEFINE('THMV_ALOHA_PLUGIN_NAME','Aloha Powerpack');
DEFINE('THMV_ALOHA_PLUGIN_SLUG','aloha-powerpack');
DEFINE('ALOHA_MORE_INFO_TEXT','More Info');
DEFINE('ALOHA_MORE_INFO_LINK','https://link.bellevuetheme.com/aloha-upgrade');
DEFINE('BELLEUVUE_PLUGINS_REMOTE_URL', 'https://link.bellevuetheme.com');
DEFINE('THMV_OPTION_TREE_FILE','option-tree/ot-loader.php');
DEFINE('THMV_WIDGET_PACK_PLUGIN_FILE','th-widget-pack/th-widget-pack.php');
DEFINE('THMV_WIDGET_PACK_ACTIVATION_ERROR_NOTICE', __('The Widget Pack plugin is no longer supported. Aloha Powerpack has replaced it.','bellevue'));
if(!defined('ALOHA_CURL_ERROR_HELP_URL')){
DEFINE('ALOHA_CURL_ERROR_HELP_URL','https://help.bellevuetheme.com/article/290-how-to-fix-curl-error-28-connection-timed-out');
}
include_once ABSPATH . 'wp-admin/includes/plugin.php';
include( get_template_directory() . '/lib/init.php'); // Initial theme setup and constants
include( get_template_directory() . '/lib/wrapper.php'); // Theme wrapper class
include( get_template_directory() . '/lib/config.php'); // Configuration
include( get_template_directory() . '/lib/titles.php'); // Page titles
include( get_template_directory() . '/lib/cleanup.php'); // Cleanup
include( get_template_directory() . '/lib/nav.php'); // Custom nav modifications
include( get_template_directory() . '/lib/comments.php'); // Custom comments modifications
include( get_template_directory() . '/lib/widgets.php'); // Sidebars and widgets
include( get_template_directory() . '/lib/scripts.php'); // Scripts and stylesheets
include( get_template_directory() . '/lib/custom.php'); // Custom functions
if (is_admin()) {
include_once( get_template_directory() . '/lib/class-tgm-plugin-activation.php'); // Bundled Plugins
require_once( get_template_directory() . '/lib/session.php'); //load session manager
require_once( get_template_directory() . '/lib/thmv_registration_setup.php'); //load session manager
if (th_aloha_active()) {
require_once( get_template_directory() . '/lib/aloha_overrides.php'); // Mailchimp functions
require_once( get_template_directory() . '/lib/registration_update.php'); // Registration functions
} else {
if(get_option('envato_setup_complete', false)){
th_aloha_installation_setup();
}
}
//if installation page, load plugins
th_template_plugins_installation_setup();
}
if(th_aloha_active()){
include( get_template_directory() . '/lib/gutenberg-compat.php');
}
if (th_show_kirki()) {
add_action('customize_controls_enqueue_scripts', 'th_custom_notification_enqueue_scripts');
function th_custom_notification_enqueue_scripts() {
$handle = 'th-options-moved-custom-notification';
wp_register_script($handle, get_template_directory_uri() . '/assets/js/th-options-moved-custom-notification.js', array('customize-controls'));
$translated_msg = array(
'msg' => esc_html('Some theme options have been moved.', 'bellevue') . '
'
. ''
. esc_html('Learn More.', 'bellevue') . '',
);
wp_localize_script($handle, 'th_customizer_notification', $translated_msg);
wp_enqueue_script($handle);
}
}
/**
* if any old options are there, show kirki
* @return type
*/
function th_show_kirki(){
return is_plugin_active('kirki/kirki.php');
}
add_action('after_setup_theme', 'th_after_setup_theme');
/**
* import old theme mods
*/
function th_after_setup_theme() {
//check if older theme, if so,
$old_mods = get_option("theme_mods_bellevue", false);
//check if older theme mods exist
if (is_array($old_mods) && count($old_mods)) {
$theme_slug = get_option('stylesheet');
update_option("theme_mods_$theme_slug", $old_mods);
delete_option("theme_mods_bellevue");
}
}
// Return theme version
function thmv_get_theme_version() {
$theme = wp_get_theme();
$themeToCheck = $theme->parent() ? $theme->parent() : $theme;
return $themeToCheck->get('Version');
}
function thmv_get_theme_version_history() {
$thmv_version_history = get_option('thmv_version_history', []);
//BUG FIX - if no thmv_first_activation_log and no thmv_first_activation_version then it means it's an old buggy installation as since 4.0 we set the option correctly
$legacy_version_to_add = false;
$child_path = ABSPATH.'wp-content/themes/bellevuex-child/style.css';
if(file_exists($child_path)){
$headers = get_file_data( $child_path, ['Version'=> 'Version'], 'theme' );
if(isset($headers['Version']) && $headers['Version']<4){
$legacy_version_to_add = $headers['Version'];
}
}
//check for older theme mods
$old_mods = get_option("theme_mods_bellevue", false);
//if no thmv_first_activation_version OR a legacy version found and is not in the theme history
if (get_option('thmv_first_activation_version') === false
|| ($legacy_version_to_add && !in_array($legacy_version_to_add, $thmv_version_history))
|| (is_array($old_mods) && count($old_mods))
) {
if(!$legacy_version_to_add){
$legacy_version_to_add = '3.5.11';
}
update_option('thmv_first_activation_log', true);
update_option('thmv_first_activation_version', $legacy_version_to_add);
$thmv_version_history = array_merge([$legacy_version_to_add], $thmv_version_history);
}
//BUG FIX end
$legacy_version = get_option('thmv_first_activation_version');
$current_version = thmv_get_theme_version();
$last_history_version = false;
if (empty($current_version)) {
return [];
}
if (!count($thmv_version_history)) {
//if an old option is found, keep it
if ($legacy_version) {
$thmv_version_history[] = $legacy_version;
}
//we must keep the current version in the history so if someone updates via FTP, we still have it in the history
$thmv_version_history[] = $current_version;
} else if (count($thmv_version_history)) {
//the history exists, check if the current version is the latest (at the top)
$lastIndex = count($thmv_version_history) - 1;
$last_history_version = $thmv_version_history[$lastIndex];
if ($last_history_version !== $current_version) {
$thmv_version_history[] = $current_version;
}
}
update_option('thmv_version_history', $thmv_version_history);
return $thmv_version_history;
}
/** since 4.0
* get the version when the template was installed for the first time
*/
function thmv_get_template_first_install_version() {
$thmv_version_history = thmv_get_theme_version_history();
if (count($thmv_version_history)) {
return $thmv_version_history[0];
}
return false;
}
/**
*
* get the theme version before this current one
*/
function thmv_get_template_previous_install_version(){
$thmv_version_history = thmv_get_theme_version_history();
//@todo, should the history be ordered?? I don't think so as this could be used for providing support
//the history is set, now we get the last version (latest - 2) if more than 1 versions exist
$history_length = count($thmv_version_history);
if(!$history_length){
return false;
}
if($history_length>1){
return $thmv_version_history[$history_length-2];
}
//otherwise just return the last one (current)
return $thmv_version_history[$history_length-1];
}
function th_template_plugins_installation_setup(){
$plugins = [];
$allPlugins = the_plugin_list($plugins, true);
$TGMPA_ID = 'bellevue_install';
$config = array(
'id' => $TGMPA_ID, // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => false, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa($allPlugins, $config);
}
add_action('wp_ajax_is_aloha_installed', 'ajax_is_aloha_installed');
add_action('wp_ajax_is_aloha_active', 'ajax_is_aloha_active');
function ajax_is_aloha_installed(){
$json = array('result'=>th_aloha_installed());
wp_send_json($json);
}
function ajax_is_aloha_active(){
$json = array('result'=>th_aloha_active());
wp_send_json($json);
}
function th_aloha_installation_setup() {
include_once( get_template_directory() . '/lib/class-tgm-plugin-activation.php'); // Bundled Plugins
//register tgmpa for installing aloha powerpack
$TGMPA_ID = 'aloha';
$aloha = array(
'name' => THMV_ALOHA_PLUGIN_NAME,
'slug' => THMV_ALOHA_PLUGIN_SLUG,
'required' => true,
'source' => 'https://link.bellevuetheme.com/'.THMV_ALOHA_PLUGIN_SLUG,
);
$config = array(
'id' => $TGMPA_ID, // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => false, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa(array($aloha), $config);
}
function th_aloha_installed() {
return file_exists(WP_PLUGIN_DIR . '/'.THMV_ALOHA_PLUGIN_FILE);
}
function th_aloha_active() {
return is_plugin_active(THMV_ALOHA_PLUGIN_FILE);
}
add_action('admin_bar_init', 'th_disallow_widget_pack_activation');
function th_disallow_widget_pack_activation(){
if(isset($_GET['action']) && $_GET['action']==='activate' && isset($_GET['plugin']) && $_GET['plugin']===THMV_WIDGET_PACK_PLUGIN_FILE){
add_option('th_widget_pack_activation_error_to_show', true);
wp_redirect(admin_url( 'plugins.php' ));
exit;
}
if(get_option('th_widget_pack_activation_error_to_show',false)){
delete_option('th_widget_pack_activation_error_to_show');
add_action('admin_notices', 'th_widget_pack_activation_error');
}
}
function th_widget_pack_activation_error(){
$class = 'notice-warning notice';
printf('
%2$s
%2$s
%3$s